package com.jqb.struts2lab01.action;

import java.util.Arrays;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ScopeAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	public String execute() {
		/**
		 * 为Scope添加值(一般都用这种方式)
		 */
		ActionContext act = ActionContext.getContext();
		act.getApplication().put("app", "applicationScope");
		act.getSession().put("ses", "sessionScope");
		act.put("reqlist", Arrays.asList("requestValue1","requestValue2"));
		
		return SUCCESS;
	}

	/**
	 * 通过叹号访问此方法
	 * */
	public String getServletAPI() {
		/**
		 * 获取ServletAPI
		 */
		HttpServletRequest req = ServletActionContext.getRequest();
		ServletContext sct=ServletActionContext.getServletContext();
		req.setAttribute("reqlist", Arrays.asList("Scope of request Value1","Scope of request Value2"));
		req.getSession().setAttribute("ses", "Scope of Session");
		sct.setAttribute("app", "Scope of Application");

		return SUCCESS;
	}
}
